package com.azure.bigstore.service;

import com.azure.bigstore.entity.Cart;
import com.azure.bigstore.repository.CartRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by liuhuaibin on 2018/1/23.
 */
@Service
public class CartService {

    @Autowired
    private CartRepository cartRepository;

    public List<Cart> getCartsByUid(long uid){
        return cartRepository.findByUid(uid);
    }
    public List<Cart> getCarts(){
        return cartRepository.findAll();
    }

    public Cart getCart(String id){
        return cartRepository.findOne(Long.valueOf(id));
    }

    public Cart saveCart(Cart cart){
        return cartRepository.save(cart);
    }

    public void deleteCart(String id){
        cartRepository.delete(Long.valueOf(id));
    }
}
